package com.zsx.servlet;

import com.zsx.entities.User;
import com.zsx.service.admin.ImpAllUser;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet(urlPatterns = "/adminService")
public class AdminService extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String choose = req.getParameter("choose");
        if (choose.equals("toIndex")){
            resp.sendRedirect("index.jsp");
        }else if (choose.equals("toLook")){
            ImpAllUser impAllUser=new ImpAllUser();
            List<User> allUser = impAllUser.getAllUser();
            req.setAttribute("users",allUser);
            req.getRequestDispatcher("allUser.jsp").forward(req,resp);
        }else {
            resp.sendRedirect("index.jsp");
        }

    }
}
